package com.jxt.myjxtmanager.ui.model;

import android.content.Context;
import android.os.Handler;
import android.os.Message;

import com.google.gson.Gson;
import com.jxt.myjxtmanager.entity.StuClassShowBean;
import com.jxt.myjxtmanager.entity.StuClassShowListBean;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by qm on 2017/3/6 0006.
 */
public class StuClassShowMo {
    /**
     * 总数据
     */
    private List<StuClassShowBean> queryList;
    private final Context context;
    private OnFindAllDataListener onFindAllDevicesListener;

    private String str = "{\n" +
            "    \"code\": 1,\n" +
            "    \"error_code\": 0,\n" +
            "    \"is_msg\": 0,\n" +
            "    \"result\": [\n" +
            "        {\n" +
            "            \"class_Id\": \"LQC100022305\",\n" +
            "            \"className\": 三年级七班,\n" +
            "            \"classLeader\": 张三丰,\n" +
            "            \"health\": 良好,\n" +
            "            \"discipline\": 80分,\n" +
            "            \"roadTeam\": \"80分\",\n" +
            "            \"updateTime\": 2017-03-06\n" +
            "        },\n" +
            "        {\n" +
            "            \"class_Id\": \"LQC100022306\",\n" +
            "            \"className\": 三年级五班,\n" +
            "            \"classLeader\": 张三丰,\n" +
            "            \"health\": 良好,\n" +
            "            \"discipline\": 85分,\n" +
            "            \"roadTeam\": \"80分\",\n" +
            "            \"updateTime\": 2017-03-06\n" +
            "        },\n" +
            "        {\n" +
            "            \"class_Id\": \"LQC100022307\",\n" +
            "            \"className\": 三年级三班,\n" +
            "            \"classLeader\": 张三丰,\n" +
            "            \"health\": 良好,\n" +
            "            \"discipline\": 80分,\n" +
            "            \"roadTeam\": \"80分\",\n" +
            "            \"updateTime\": 2017-03-06\n" +
            "        },\n" +
            "        {\n" +
            "            \"class_Id\": \"LQC100022308\",\n" +
            "            \"className\": 三年级一班,\n" +
            "            \"classLeader\": 张三丰,\n" +
            "            \"health\": 优秀,\n" +
            "            \"discipline\": 80分,\n" +
            "            \"roadTeam\": \"80分\",\n" +
            "            \"updateTime\": 2017-03-06\n" +
            "        },\n" +
            "        {\n" +
            "            \"class_Id\": \"LQC100022309\",\n" +
            "            \"className\": 三年级六班,\n" +
            "            \"classLeader\": 张三丰,\n" +
            "            \"health\": 脏乱差,\n" +
            "            \"discipline\": 90分,\n" +
            "            \"roadTeam\": \"85分\",\n" +
            "            \"updateTime\": 2017-03-06\n" +
            "        }\n" +
            "    ],\n" +
            "    \"msg\": null,\n" +
            "    \"success\": true,\n" +
            "    \"failed\": false,\n" +
            "    \"error\": false\n" +
            "}";

    public StuClassShowMo(Context context) {
        this.context = context;
        queryList = new ArrayList<>();
        mGson = new Gson();
    }

    public List<StuClassShowBean> getQueryList() {
        return queryList;
    }
    public void RequestData() {

//        HttpClient.getInstance().httpCheckWorkInfo(context, new ResultCallback() {
//            @Override
//            public void onFailure(Request request, Exception e) {
//                super.onFailure(request, e);
//            }
//
//            @Override
//            public void onError(int code, String message) {
//                super.onError(code, message);
//            }
//
//            @Override
//            public void onResponse(Object response) {
//                super.onResponse(response);
//            }
//
//            @Override
//            public void onResponse(int code, String msg) {
//                super.onResponse(code, msg);
//            }
//
//            @Override
//            public void onFinish() {
//                super.onFinish();
//            }
//
//            @Override
//            public void onStart() {
//                super.onStart();
//            }
//        });

        loadData();
    }

    private Gson mGson;

    private void loadData() {
        //模拟网络加载
        Message message = new Message();
        message.arg1 = 2;
        loadDataHandler.sendMessageDelayed(message, 1000);
    }

    private Handler loadDataHandler = new Handler() {
        @Override
        public void handleMessage(Message msg) {

            StuClassShowListBean mResult = mGson.fromJson(str, StuClassShowListBean.class);
            queryList = mResult.getResult();
            onFindAllDevicesListener.onFindSuccess();
        }
    };


    public void setOnFindAllDevicesListener(OnFindAllDataListener onFindAllDevicesListener) {
        this.onFindAllDevicesListener = onFindAllDevicesListener;
    }

    /**
     * 请求监听
     */
    public interface OnFindAllDataListener {
        void onFindSuccess();

        void OnFindAllDataSuccess(String strTitle);

        void onFailure();

        void onError();
    }
}
